﻿using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
using System.IO;

namespace Mixr
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new UserPopup());
        }
    }


    //Movie class, contains all information about a specific movie
    public class Movie
    {
        //Constructor for Movie
        public Movie(int uid, string utitle, string uyear, string uurl, Image i, DirectoryInfo info)
        {
            cur_id = uid;
            cover = i;
            title = utitle;
            year = uyear;
            url = uurl;
            location = info;
        }

        //constructor, creates default image, and contains location of specific movie
        public Movie(string uurl, DirectoryInfo ulocation)
        {
            url = uurl;
            location = ulocation;
            cover = global::Mixr.Properties.Resources.mixr;
        }

        //Default constructor, just gives default cover image
        public Movie()
        {
            cover = global::Mixr.Properties.Resources.mixr;
        }

        public Image getImage() { return cover; }
        public string getUrl() { return url; }
        
        public string output() { string output = title + " (" + year + ")"; return output; }

        public int cur_id;
        public string title;
        public List<string> genres;
        public DirectoryInfo location;
        public string locationString;
        public string quality;
        public string rating;
        public string year;
        public string director;
        public string writer;
        public string description;
        public string url;
        public Image cover;
        public int coverSize;

        public int DumpMovieToDatabase() //Function that takes the current movie object and dumps it to the user's Movie database. Returns 0 if it failed/already exists, 1 if it succeeded.
        {
            string conn
                = @"Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\UserDatabase.mdf';Integrated Security=True;User Instance=True";
            string insert_query
                = "INSERT INTO [Movie] (UserID, Title, Genre, FileLoc, Quality, Rating, Year, Director, Writer, Description, Cover, CoverSize) VALUES (" + cur_id + ", '" + title + "', '" + genres[0] + "', '" + locationString.Trim() + "', '" + quality + "', '" + rating + "', " + Convert.ToInt16(year) + ", '" + director + "', '" + writer + "', '" + description + "', '" + cover + "', '" + coverSize + "')";

            SqlConnection connection = new SqlConnection(conn);
            SqlCommand insert_movie = new SqlCommand(insert_query, connection);

            connection.Open();
            int was_success = insert_movie.ExecuteNonQuery();
            connection.Close();
            return was_success;
        }
    }
}

